package model;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;


/**
 * 
 * @author Nelly-Kim TRAN
 * 
 * 
 * @param contacts
 * 				Set of contacts to keep track and manipulate the profiles (add, delete, modify)
 * 
 * @param fichier
 * 				File to store all the contacts permanently 
 *
 */

public class Adressbook {
	
	//public static File csvFile;  
	public static Set contacts;
	public static File fichier;

	public Adressbook() {
		contacts=new HashSet(100);
		fichier=new File("monfichier2.txt");
		try {
			fichier.createNewFile();
		} catch (IOException e2) {
			e2.printStackTrace();
		}
		
		//retrieves the contacts from the csv file
		BufferedReader br = null;
		String line = "";
		String cvsSplitBy = ",";

	try {
		 
		br = new BufferedReader(new FileReader("monfichier2.txt"));
		while ((line = br.readLine()) != null) {
			System.out.println("no contacts uploaded from the txt file");
		        // use comma as separator
			String[] contact = line.split(cvsSplitBy);
			contacts.add(new Contact(contact[0], contact[1],contact[2], contact[3], contact[4], contact[5], contact[6], contact[7],
					contact[8], contact[9], contact[10], contact[11], contact[12]));
		}
		
	} catch (FileNotFoundException e1) {
		e1.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	} finally {
		if (br != null) {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	}

	
	

}
